/*
 * 项目名称:    wms-server-jeecg
 * 创建人员:    FanZhiwen
 * 创建时间:    2023-12-05
 */
package org.jeecg.modules.business.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.business.doc.business.entity.WmsInReceipt;
import org.jeecg.modules.business.doc.business.service.IWmsInReceiptService;
import org.jeecg.modules.flow.callback.enums.TransferStatusEnum;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 定时任务过账
 *
 * @author FanZhiwen
 * @version 1.0.0
 * @since 2023-12-05
 */
@Service
@Slf4j
public class TransferJob implements Job {
    @Autowired
    private IWmsInReceiptService wmsInReceiptService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("定时过账任务开始执行......");
        List<WmsInReceipt> list = wmsInReceiptService.list(new LambdaQueryWrapper<WmsInReceipt>()
                .in(WmsInReceipt::getTransferSapStatus, Arrays.asList(TransferStatusEnum.NOT_TRANSFER.getCode(),TransferStatusEnum.TRANSFER_FAIL.getCode()))
        );
        for (WmsInReceipt wmsInReceipt : list) {
            wmsInReceiptService.inReceiptTransfer(wmsInReceipt.getId());
        }
    }
}
